﻿// -------------------------------------------------------------------------------------------------
// <copyright file="TVEpisode.cs" company="HeterogeneousComputing.com">
// Creative Commons Attribution-ShareAlike 3.0 Unported License
// </copyright>
//
// <author>Jock</author>
//
// <date>04/08/2011</date>
//
// <summary>Implements the tv episode class</summary>
// -------------------------------------------------------------------------------------------------
namespace TheTVDBScraper
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization; 
    using System.Text;

    /// <summary>
    /// Class representing a particular Episode within a Season of a TVSeries.
    /// </summary>
    [DataContract(Name = "TVEpisode",
        Namespace = "http://www.heterogeneouscomputing.com/TheTVDBScraper", IsReference = true)]
    public class TVEpisode : IJobRoleCapable, IExtensibleDataObject
    {
        #region Private Fields

            /// <summary> The extension data object value. </summary>
            private ExtensionDataObject extensionDataObject_value;

            /// <summary>
            /// The Id of this Episode.
            /// </summary>
            private string id;

            /// <summary> The name of the TVEpisode. </summary>
            private string episodeName;

            /// <summary> The number of the TVEpisode. </summary>
            private string episodeNumber;

            /// <summary> The description or Overview of this TVEpisode. </summary>
            private string overview;

            /// <summary> List of Directors for this TVEpisode.  </summary>
            private Dictionary<string, JobRole> jobRoleDictionary = new Dictionary<string, JobRole>();
        #endregion

        #region Constructors

            /// -------------------------------------------------------------------------------------------------
            /// <summary>   Initializes a new instance of the TVEpisode class. </summary>
            /// <param name="episodeId">    Identifier for the episode. </param>
            /// -------------------------------------------------------------------------------------------------
            internal TVEpisode(string episodeId)
            {
                this.id = episodeId;
            }

            /// -------------------------------------------------------------------------------------------------
            /// <summary>   Prevents a default instance of the TVEpisode class from being created. </summary>
            /// -------------------------------------------------------------------------------------------------
            private TVEpisode()
            {
            }
        #endregion

        #region Public Properties
            /// -------------------------------------------------------------------------------------------------
            /// <summary>   Gets or sets the structure that contains extra data. 
            /// To implement the IExtensibleDataObject interface,
            /// you must implement the ExtensionData property. The property
            /// holds data from future versions of the class for backward
            /// compatibility.</summary>
            /// <value> Information describing the extension. </value>
            /// ### <returns>
            /// An <see cref="T:System.Runtime.Serialization.ExtensionDataObject" /> that contains data that
            /// is not recognized as belonging to the data contract.
            /// </returns>
            /// -------------------------------------------------------------------------------------------------
            public ExtensionDataObject ExtensionData
            {
                get
                {
                    return this.extensionDataObject_value;
                }

                set
                {
                    this.extensionDataObject_value = value;
                }
            }

            /// -------------------------------------------------------------------------------------------------
            /// <summary> Gets the List of Directors for this TVEpisode. </summary>
            /// <value> The directors. </value>
            /// -------------------------------------------------------------------------------------------------
            [DataMember(EmitDefaultValue = false)]
            public List<Director> Directors
            {
                get
                {
                    List<Director> retVal = new List<Director>();
                    var directors =
                        from person in this.jobRoleDictionary.Values
                            where (person is Director)
                                select person;
                    foreach (var director in directors)
                    {
                        retVal.Add((Director)director);
                    }

                    return retVal;
                }
            }

            /// -------------------------------------------------------------------------------------------------
            /// <summary>   Gets the writers associated with this TVEpisode. </summary>
            /// <value> The writers. </value>
            /// -------------------------------------------------------------------------------------------------
            [DataMember(EmitDefaultValue = false)]
            public List<Writer> Writers
            {
                get
                {
                    List<Writer> retVal = new List<Writer>();
                    var writers =
                        from person in this.jobRoleDictionary.Values
                        where (person is Writer)
                        select person;
                    foreach (var writer in writers)
                    {
                        retVal.Add((Writer)writer);
                    }

                    return retVal;
                }
            }

            /// -------------------------------------------------------------------------------------------------
            /// <summary>   Gets the guest stars (Actors) for this episode. </summary>
            /// <value> The guest stars. </value>
            /// -------------------------------------------------------------------------------------------------
            [DataMember(EmitDefaultValue = false)]
            public List<Actor> GuestStars
            {
                get
                {
                    List<Actor> retVal = new List<Actor>();
                    var actors =
                        from person in this.jobRoleDictionary.Values
                        where (person is Actor)
                        select person;
                    foreach (var actor in actors)
                    {
                        retVal.Add((Actor)actor);
                    }

                    return retVal;
                }
            }
        #endregion

        #region Public Properties

            /// -------------------------------------------------------------------------------------------------
            /// <summary>   Gets or sets the TVEpisode identifier. </summary>
            /// <value> The identifier. </value>
            /// -------------------------------------------------------------------------------------------------
            [DataMember]
            public string Id
            {
                get
                {
                    return this.id;
                }

                set
                {
                    this.id = value;
                }
            }

            /// -------------------------------------------------------------------------------------------------
            /// <summary>   Gets or sets the name of the episode. </summary>
            /// <value> The name of the episode. </value>
            /// -------------------------------------------------------------------------------------------------
            [DataMember(EmitDefaultValue = false)]
            public string EpisodeName
            {
                get
                {
                    return this.episodeName;
                }

                set
                {
                    this.episodeName = value;
                }
            }

            /// -------------------------------------------------------------------------------------------------
            /// <summary>   Gets or sets the episode number. </summary>
            /// <value> The episode number. </value>
            /// -------------------------------------------------------------------------------------------------
            [DataMember(EmitDefaultValue = false)]
            public string EpisodeNumber
            { 
                get
                {
                    return this.episodeNumber;
                }
                
                set
                {
                    this.episodeNumber = value;
                }
            }

            /// -------------------------------------------------------------------------------------------------
            /// <summary>   Gets or sets the description or Overview of this TVEpisode. </summary>
            /// <value> The description. </value>
            /// -------------------------------------------------------------------------------------------------
            [DataMember(EmitDefaultValue = false)]            
            public string Overview
            {
                get
                {
                    return this.overview;
                }

                set
                {
                    this.overview = value;
                }
            }
        #endregion

        #region Public Operations

            /// -------------------------------------------------------------------------------------------------
            /// <summary>   Adds jobRole e.g. Actor, Writer, Director to this TVEpisode. </summary>
            /// <remarks>    The method author was Jock, on the 07/08/2011. </remarks>
            /// <typeparam name="R">    Type of the JobRole. </typeparam>
            /// <param name="jobRole">  The job role. </param>
            /// -------------------------------------------------------------------------------------------------
            void IJobRoleCapable.Add<R>(R jobRole)
            {
                if (!this.jobRoleDictionary.ContainsKey(jobRole.Person.Name))
                {
                    this.jobRoleDictionary.Add(jobRole.Person.Name, jobRole);
                }
            }
        #endregion

        #region Internal Operations

        #endregion
    }
}

/// -------------------------------------------------------------------------------------------------
// End of TVEpisode.cs
/// -------------------------------------------------------------------------------------------------
